﻿
namespace MyFurion.Application
{
    /// <summary>
    /// 公告服务仓储
    /// </summary>
    public class NoticeRepository:BaseRepository<NoticeInfo>, ITransient
    {
        /// <summary>
        /// 查询条件
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        private Expression<Func<NoticeInfo, bool>> GetCodition(NoticeInfoPage input)
        {
            var exp = Expressionable.Create<NoticeInfo>();
            exp.AndIF(!string.IsNullOrWhiteSpace(input.Title), it => it.Title.Contains(input.Title));
            exp.AndIF(input.IsPublish.HasValue, it =>it.IsPublish==input.IsPublish.Value);
            return exp.ToExpression();
        }
        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<PageResult<NoticeInfo>>GetPageList(NoticeInfoPage input)
        {
            var whereExp = GetCodition(input);
            return await GetPageListAsync(whereExp, input.PageIndex, input.PageSize, it => it.CreateTime);
        }
        /// <summary>
        /// 获取数据列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<List<NoticeInfo>> GetDataList(NoticeInfoPage input)
        {
            var whereExp = GetCodition(input);
            return await GetList(whereExp, it => it.CreateTime);
        }
    }
}
